// Package sys
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2025 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.15.11
package sys

import (
	"context"
	"hotgo/api/admin/receiveraddress"
	"hotgo/internal/model/input/sysin"
	"hotgo/internal/service"
)

var (
	ReceiverAddress = cReceiverAddress{}
)

type cReceiverAddress struct{}

// List 查看收货地址列表
func (c *cReceiverAddress) List(ctx context.Context, req *receiveraddress.ListReq) (res *receiveraddress.ListRes, err error) {
	list, totalCount, err := service.SysReceiverAddress().List(ctx, &req.ReceiverAddressListInp)
	if err != nil {
		return
	}

	if list == nil {
		list = []*sysin.ReceiverAddressListModel{}
	}

	res = new(receiveraddress.ListRes)
	res.List = list
	res.PageRes.Pack(req, totalCount)
	return
}

// Edit 更新收货地址
func (c *cReceiverAddress) Edit(ctx context.Context, req *receiveraddress.EditReq) (res *receiveraddress.EditRes, err error) {
	err = service.SysReceiverAddress().Edit(ctx, &req.ReceiverAddressEditInp, false)
	return
}

// View 获取指定收货地址信息
func (c *cReceiverAddress) View(ctx context.Context, req *receiveraddress.ViewReq) (res *receiveraddress.ViewRes, err error) {
	data, err := service.SysReceiverAddress().View(ctx, &req.ReceiverAddressViewInp)
	if err != nil {
		return
	}

	res = new(receiveraddress.ViewRes)
	res.ReceiverAddressViewModel = data
	return
}

// Delete 删除收货地址
func (c *cReceiverAddress) Delete(ctx context.Context, req *receiveraddress.DeleteReq) (res *receiveraddress.DeleteRes, err error) {
	err = service.SysReceiverAddress().Delete(ctx, &req.ReceiverAddressDeleteInp, false)
	return
}
